package com.nimble.smile.service;

/**
 * error code definition
 * error code长度6位
 * for example
 * code--50010201
 * 第一位--5,标志位，无意义
 * 第二位，第三位，第四位--001，表示某个类的编码（例如service，controller类）
 * 第五位，第六位--02，表示所在类的错误编码（例如UserService中changePassword方法）
 */
public enum OperationCode {

    //通用类型--
    FAIL(0, "fail"),
    SUCCESS(1, "success"),


    //common-5000xx
    INVALID_KEY(500001, "key已失效"),
    PARAMS_ERROR(500002, "参数有误"),
    RESOURCE_INT_ERROR(500003, "buffer reader exception"),
    BUFFER_METHOD_ERROR(500004, "请求方法错误"),
    ENUM_TYPE_NOT_FIND(500005, "enum type找不到"),
    DATA_NOT_EXIST(500006,"数据不存在"),
    DATA_ERROR(500007, "数据错误"),
    DATA_EXIST(500008,"数据已存在"),
    INIT_SCORES_ERROR(500009, "初始化排名信息出错"),

    //Auth 5001xx
    AUTH_THIRD_PLATFORM_EXISTED(500101, "第三方账户已经存在"),
    AUTH_TOKEN_EXPIRED(500102, "token已过期"),
    AUTH_TOKEN_ERROR(500103, "token错误"),
    AUTH_NEED_AUTH_AGAIN(500104, "需要重新认证或登陆"),
    AUTH_UNAUTHORIZED(500105, "无权操作"),
    AUTH_HAS_LOGIN_BY_OTHER(500106, "该账户已在其它地方登陆"),
    AUTH_COMPRISED(500107, "Sucker,your ip has been locked,missile is on the way"),
    AUTH_PASSWORD_ERROR(500108, "   密码错误"),
    AUTH_UNKNOWN_SOURCE(500109, "来源不明"),
    AUTH_THIRD_NOT_EXISTED(500110, "第三方账户不存在"),
    AUTH_THIRD_MOBILE_NOT_BOUND(500111, "尚未绑定手机号"),
    AUTH_THIRD_MOBILE_ALREADY_BOUND(500112, "该账号已经绑定手机号"),
    AUTH_THIRD_AUTH_SAME_TYPE_EXISTED(500113, "已经绑定相同类型的第三方账号"),


    //用户信息--5002xx
    USER_NOT_EXISTS(500201, "用户不存在"),
    USER_PASSWORD_ERROR(500202, "密码错误"),
    USER_EMPTY_USERNAME_OR_PWD(500203, "用户名或密码为空"),
    USER_LOCKED(500204, "用户锁定"),
    USER_ACCOUNT_ABNORMAL(500205, "账户异常"),
    USER_INCORRECT_CAPTCHA(500206, "验证码不正确"),
    USER_ROLE_ERROR(500207, "用户角色错误"),
    USER_NOT_AUTHORIZED(500208, "未被授权"),
    USER_MOBILE_EXISTED(500209, "该手机号已注册"),
    USER_MOBILE_NOT_EXIST(500210, "该手机号未注册"),
    USER_NICKNAME_EXISTED(500211, "昵称已存在，请选择其他昵称"),
    PASSWORD_FORMAT_ERROR(500212, "密码格式错误"),



    //role 5003xx
    ROLE_NOT_EXISTS(500301, "角色不存在"),

    //emotion
    EMOTION_EVALUATE_ERROR(500401, "评分系统调用出错"),
    EMOTION_IMG_NOT_RECOGNIZABLE(500402, "图像无法识别，请重新拍照上传"),



    //sms 5007XX
    SMS_SEND_FAILED(500701, "短信发送失败，请稍后再试"),
    SMS_TEMPLATE_PARAM_ERROR(500702, "短信模版参数错误"),
    SMS_CODE_NOT_IDENTICAL(500703, "短信验证码错误"),
    SMS_CODE_EXPIRED(500704, "短信验证码已失效"),

    //七牛--5011xx
    QINIU_SERVER_ERROR(501101, "七牛服务器错误"),
    QINIU_FORMAT_ERROR(501102, "数据格式错误"),
    QINIU_SIZE_ERROR(501103, "数据大小超出限制"),
    QINIU_RESOURCE_EXISTS(501104, "数据已存在"),
    QINIU_NETWORK_ERROR(501105, "网络异常,请重新上传"),



    ;
    private final int value;

    private String reason;

    OperationCode(int value, String reason) {
        this.value = value;
        this.reason = reason;
    }

    public static OperationCode valueOf(int errorCode) {
        for (OperationCode type : values()) {
            if (type.value == errorCode) {
                return type;
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + errorCode + "]");
    }

    public int getValue() {
        return value;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }


}
